# 定义要安装的功能
$features = @(
    "NET-Framework-Features",
    "NET-Framework-Core",
    "NET-Framework-45-Features",
    "NET-Framework-45-Core",
    "NET-Framework-45-ASPNET",
    "NET-WCF-Services45",
    "NET-WCF-HTTP-Activation45",
    "NET-WCF-TCP-PortSharing45",
    "NET-Framework-35-Core"  # 添加 .NET Framework 3.5
)

# 安装指定的功能
$result = Install-WindowsFeature -Name $features -IncludeManagementTools

# 检查安装结果
if ($result.Success) {
    Write-Host "以下功能已成功安装：" -ForegroundColor Green
    foreach ($feature in $result.FeatureResult) {
        Write-Host "- $($feature.DisplayName)" -ForegroundColor Green
    }
    
    # 检查是否需要重启
    if ($result.RestartNeeded -eq "Yes") {
        Write-Host "警告：需要重启服务器以完成安装。" -ForegroundColor Yellow
    }
} else {
    Write-Host "安装过程中出现错误。以下是失败的功能：" -ForegroundColor Red
    foreach ($feature in $result.FeatureResult | Where-Object {$_.Success -eq $false}) {
        Write-Host "- $($feature.DisplayName)" -ForegroundColor Red
    }
}

# 显示已安装功能的详细信息
Write-Host "已安装的功能详情：" -ForegroundColor Cyan
Get-WindowsFeature | Where-Object {$_.Installed -eq $true -and $_.Name -in $features} | Format-Table Name, DisplayName, InstallState